package com.example.w4k;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

import java.text.DecimalFormat;

public class MainActivity extends AppCompatActivity {

    public  void  ButtonClick(View v){
        EditText Height = (EditText)findViewById(R.id.height);
        EditText Weight = (EditText)findViewById(R.id.weight);
        TextView Result = (TextView)findViewById(R.id.txt);
    ////得加上判断身高体重是否为空
        Double height = Double.parseDouble(Height.getText().toString());
        Double weight = Double.parseDouble(Weight.getText().toString());

        Double bmi = weight / (height*height);
        DecimalFormat df = new DecimalFormat(".00");

            if(bmi<18.5){
               Result.setText("BMI为"+df.format(bmi)+"，您的体重偏轻");
            }
            else  if(bmi<=24.9){
                Result.setText("BMI为"+df.format(bmi)+"，您的体重正常");
            }
            else if(bmi<=29.9){
                Result.setText("BMI为"+df.format(bmi)+"，您的体重偏重");
            }
            else if (bmi<=34.9){
                Result.setText("BMI为"+df.format(bmi)+"，您的体重肥胖!");
            }
            else if (bmi<=39.9){
                Result.setText("BMI为"+df.format(bmi)+"，您的体重过于肥胖!!");
            }
            else {
                Result.setText("BMI为"+df.format(bmi)+"，您的体重严重肥胖!!!");
            }

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}